import numpy as np
import math
import matplotlib.pyplot as plt

step = (1.01 - 0.99) / 100
points = np.arange(0.99, 1.01+step, step)


def f(x):
    y = math.pow(x, 8) - 8 * math.pow(x, 7) + 28 * math.pow(x, 6) - 56 * math.pow(x, 5) + 70 * math.pow(x, 4) - 56 * math.pow(x, 3) + 28 * math.pow(x, 2) - 8 * x + 1
    return y


def g(x):
    y = (((((((x - 8) * x + 28) * x - 56) * x + 70) * x - 56) * x + 28) * x - 8) * x + 1
    return y


def h(x):
    y = math.pow((x - 1), 8)
    return y


f_values = []
g_values = []
h_values = []


for i in range(101):
    f_values.append(f(points[i]))
    g_values.append(g(points[i]))
    h_values.append(h(points[i]))

plt.plot(points, f_values)
plt.plot(points, g_values)
plt.plot(points, h_values)
plt.legend(['f(x)', 'g(x)', 'h(x)'], loc='upper left')
plt.savefig('./pic/problemA.png')
plt.show()

